
#include "ViewModelWindow.h"

#include "../leak.h"

using namespace std;


ViewModelWindow::ViewModelWindow() : MyBaseWindow( "ViewModel", 500, 500, FULL_SCR_ENABLED|RESIZABLE|MINIMIZABLE|CLOSABLE), cam_rot_enabled_(false),
									 main_viewport_( -0.9f, -0.5f, 1.8f, 0.5f, window_size_){
		//main_viewport_.reset(new MyGLView( -0.9f, -0.5f, 1.8f, 0.5f, window_size_));


		update_needed_ = true;
		OnMove( 0.0f, 0.0f );

	}

/*
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
                          WPARAM wParam, LPARAM lParam)
{

	bool b;

    switch (message)
    {
    case WM_CREATE:
        return 0;
    case WM_CLOSE:
        PostQuitMessage (0);
        return 0;

    case WM_DESTROY:
        return 0;

    case WM_KEYDOWN:

		b = true;
		cout << "key: " << wParam << endl;
		if( !g_pressed_keys.empty() )
		for( auto key = g_pressed_keys.begin(); key != g_pressed_keys.end(); key++ )
		{
			if( *key == wParam )
			{
				b = false;
			}
			//cout << "key: " << *key << endl;
		}

		if(b)
		{
			g_pressed_keys.push_back( wParam );
		}

		key_press_signal.Fire( g_pressed_keys );

        return 0;

	case WM_KEYUP:

		if( !g_pressed_keys.empty() )
		{
		//for( auto key = g_pressed_keys.begin(); key != g_pressed_keys.end(); key++ )
		auto key = g_pressed_keys.begin();
		while( key != g_pressed_keys.end() )
		{
			if( *key == wParam )
			{
				cout << "same key: " << *key << endl;
				key = g_pressed_keys.erase( key );
				//key--;
			} else
			{
				key++;
			}
		}
		}
		key_press_signal.Fire( g_pressed_keys );


		switch (wParam)
        {
		case 'W':
		case 'S':
			move_vec[2] = 0.0f;
			break;
		case 'A':
		case 'D':
			move_vec[0] = 0.0f;
			break;
		case VK_SPACE:
			move_vec[1] = 0.0f;
			return 0;
		}

	case WM_LBUTTONDOWN:
		switch (wParam)
        {
		case MK_LBUTTON:
			SetCapture(hWnd);

			RECT rect;
			GetWindowRect(hWnd, &rect);

			POINT p;

			if ( GetCursorPos(&p) )
			{
				ScreenToClient(hWnd,&p);

				current_mouse.x = (float)p.x;
				current_mouse.y = (float)p.y;

				prev_mouse.x = (float)p.x;
				prev_mouse.y = (float)p.y;
			}

			click_signal.Fire(((current_mouse.x)/( rect.right - rect.left ))*2.0f - 1.0f, (-(current_mouse.y)/( rect.bottom - rect.top ))*2.0f + 1.0f);
			//click_signal.Fire(((current_mouse.x)/800.0f)*2.0f - 1.0f, (-(current_mouse.y)/800.0f)*2.0f + 1.0f);

			break;
		}
		break;
	case WM_MOUSEMOVE:


		RECT rect;
		GetWindowRect(hWnd, &rect);

		POINT p, p2;

		if ( GetCursorPos(&p) )
		{
			p2 = p;
			ScreenToClient(hWnd,&p);

			current_mouse.x = (float)p.x;
			current_mouse.y = (float)p.y;

			move_signal.Fire( ( current_mouse.x - prev_mouse.x )/(float)( (float)rect.right - rect.left ),
							  ( current_mouse.y - prev_mouse.y )/(float)( (float)rect.bottom - rect.top ) );

		}

		ScreenToClient(hWnd,&p2);
		prev_mouse.x = static_cast<float>( p2.x );
		prev_mouse.y = static_cast<float>( p2.y );

		//current_mouse.x = p2.x;
		//current_mouse.y = p2.y;

		//RedrawWindow( hWnd, 0, 0, RDW_FRAME );

		break;
	case WM_LBUTTONUP:

		ReleaseCapture();
		ShowCursor(true);


		if ( GetCursorPos(&p) )
		{
			ScreenToClient(hWnd,&p);

			current_mouse.x = (float)p.x;
			current_mouse.y = (float)p.y;

			prev_mouse.x = (float)p.x;
			prev_mouse.y = (float)p.y;
		}

		GetWindowRect(hWnd, &rect);

		move_signal.Fire( 0.0f, 0.0f );

		release_signal.Fire(((current_mouse.x)/( rect.right - rect.left ))*2.0f - 1.0f, (-(current_mouse.y)/( rect.bottom - rect.top ))*2.0f + 1.0f);
		//listen_mouse_move = false;
		break;
	case WM_MOUSEHOVER:

			cout << "00\n";
			cout << "11\n";

		break;
    default:
		return DefWindowProc (hWnd, message, wParam, lParam);
    }


	return DefWindowProc (hWnd, message, wParam, lParam);

}
*/
